﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CloudFranceTriple.WebRole.Models;

namespace CloudFranceTriple.WebRole.Areas.Gaming.Controllers
{
    public class PlayerController : BaseController
    {
        private UsersContext db = new UsersContext();

        private readonly IWebSecurityWrapper _webSecurity;
        public PlayerController()
        {
            this._webSecurity = new WebSecurityWrapper();
        }

        public PlayerController(IWebSecurityWrapper webSecurity)
            : base(webSecurity)
        {
            this._webSecurity = webSecurity;
        }
        [AllowAnonymous]
        [ChildActionOnly]
        public ActionResult ShowGravatar(Int32 id)
        {
            ViewBag.GravatarImageUrl = String.Format("https://www.gravatar.com/avatar/{0}?s=40&d=http://s19.postimage.org/62du01yov/default_avatar_82.png&r=g", base.UserGravatarHashByUserId(id));
            ViewBag.GravatarImageAlt = base.GetProfile(id).UserName;
            return PartialView("_MiniGravatar");
        }

        //
        // GET: /Gaming/Player/

        [AllowAnonymous]
        public ActionResult Index()
        {
            var query = db.UserProfiles.Where(ul => ul.ShowInNonAdminList).OrderBy(user => user.UserName).ToList();
            return View(query);
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}